package com.zte.stats.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zte.stats.dao.IStatsSalesDao;
import com.zte.stats.model.*;
import com.zte.stats.service.IStatsSalesService;
import com.zte.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class StatsSalesServiceImpl implements IStatsSalesService {

    @Autowired
    private IStatsSalesDao iStatsSalesDao;

    @Override
    public PageModel<StatsCustom> queryCustomOrdersByCondition(PageModel<StatsCustom> pageModel, StatsCustomCondition scc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsCustom> statsCustoms = iStatsSalesDao.queryCustomOrdersByCondition(scc);
        PageInfo<StatsCustom> info = new PageInfo<StatsCustom>(statsCustoms);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsCustom>(info.getList()));
        return pageModel;
    }

    @Override
    public PageModel<StatsOrders> queryOrdersByCondition(PageModel<StatsOrders> pageModel, StatsCustomCondition scc) {
        int pageNum = pageModel.getPageNum() <= 0 ? 1 : pageModel.getPageNum();
        int pageSize = pageModel.getPageSize() <= 0 ? 5 : pageModel.getPageSize();
        PageHelper.startPage(pageNum, pageSize);
        List<StatsOrders> statsOrders = iStatsSalesDao.queryOrdersList(scc);
        PageInfo<StatsOrders> info = new PageInfo<StatsOrders>(statsOrders);
        pageModel.setPageNum(info.getPageNum());
        pageModel.setPageSize(info.getPageSize());
        pageModel.setTotalPage(info.getPages());
        pageModel.setTotalCount((int) info.getTotal());
        pageModel.setData(new ArrayList<StatsOrders>(info.getList()));
        return pageModel;
    }

    @Override
    public List<StatsCity> queryCityList(StatsCustomCondition scc) {
        List<StatsCity> statsCities = iStatsSalesDao.queryCity(scc);
        return statsCities;
    }

    @Override
    public List<StatsProvince> queryProvince() {
        List<StatsProvince> statsProvinces = iStatsSalesDao.queryProvince();
        return statsProvinces;
    }
}
